<!DOCTYPE html>
<!--suppress ALL -->
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>bifurcateBy(分割)</title>
</head>

<body>
  <h4>
    Splits values into two groups according to a predicate function, which specifies which group an element in the input collection
    belongs to. If the predicate function returns a truthy value, the collection element belongs to the first group; otherwise,
    it belongs to the second group. Use Array.reduce() and Array.push() to add elements to groups, based on the value returned
    by fn for each element.
  </h4>
  <h4>
    通过Array.reduce()设置递归 [[],[]]设置了(acc, val, i)函数返回参数类型 filterAction[i] ? 0 : 1判断可以push到数组val里面
  </h4>
  <script type="text/javascript">
    const bifurcate = (arr, filterAction) =>
      //这里设置了(acc, val, i)函数返回参数类型是[[], []]
      //acc是空的数组,val是数组里面的元素,i是序列号
      arr.reduce((acc, val, i) => (acc[filterAction[i] ? 0 : 1].push(val), acc), [[], []]);
    console.log(bifurcate(["beep", "boop", "foo", "bar"], [true, true, false, true]));
    // [ ['beep', 'boop', 'bar'], ['foo'] ]
  </script>
</body>

</html>